<template>
  <div v-if="showPopup" class="popup-box-2">
    <div class="popup-body">
      <div class="body-title">
        <div>修改现金</div>
        <div
          @click="closePopup"
          class="iconfont icon-guanbi font-size-22"
        ></div>
      </div>
      <div class="body-content">
        <div class="price-box">
          <div class="flex">
            <div>已收现金</div>
            <div>{{ yishouPrice }} 元</div>
          </div>
          <div class="flex input-box active">
            <div>修改后现金</div>
            <div class="flex items-center">
              <text>{{ updatePrice }}</text>
              <text class="cursor"></text>
              <text class="m-l-4">元</text>
            </div>
          </div>
        </div>
        <div class="keyboard">
          <div @click="keyD('1')" class="jian">1</div>
          <div @click="keyD('2')" class="jian">2</div>
          <div @click="keyD('3')" class="jian">3</div>
          <div @click="keyD('4')" class="jian">4</div>
          <div @click="keyD('5')" class="jian">5</div>
          <div @click="keyD('6')" class="jian">6</div>
          <div @click="keyD('7')" class="jian">7</div>
          <div @click="keyD('8')" class="jian">8</div>
          <div @click="keyD('9')" class="jian">9</div>
          <div @click="keyD('.')" class="jian">.</div>
          <div @click="keyD('0')" class="jian">0</div>
          <div @click="keyD('退格')" class="jian">
            <span class="iconfont icon-shanchu_delete-two font-size-27"></span>
          </div>
        </div>
      </div>

      <div class="body-footer">
        <div @click="closePopup" class="cancel">取消</div>
        <div @click="closePopup" class="confirm">确定收款</div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref } from "vue";

const showPopup = ref(false);
const yishouPrice = ref("50.00");
const updatePrice = ref("20.00");
function keyD(e) {
  console.log(e);
  switch (e) {
    case "退格":
      updatePrice.value = updatePrice.value.slice(0, -1);

      break;

    case ".":
      if (!updatePrice.value.includes(".")) {
        updatePrice.value = updatePrice.value + ".";
      }
      break;

    default:
      // 保留两位小数
      if (updatePrice.value && updatePrice.value.split(".")[1]?.length >= 2)
        return;

      updatePrice.value = updatePrice.value + e;

      break;
  }
}

function open() {
  showPopup.value = true;
}

function closePopup() {
  showPopup.value = false;
}

defineExpose({ open });
</script>
<style lang="scss">
@keyframes blink {
  50% {
    opacity: 0;
  }
}
.cursor {
  width: 1px;
  height: 20rpx;
  background-color: $uni-text-color-3;
  margin-left: 1rpx;
  animation: blink 1s step-start infinite;
}

.popup-box-2 {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 999;
  .popup-body {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 754rpx;
    height: 460rpx;
    border-radius: 20rpx;
    overflow: hidden;
    background: $uni-text-color-inverse;
    display: flex;
    flex-direction: column;

    .body-title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16rpx 30rpx;
      background: $uni-text-color-inverse;
      border-bottom: 1rpx solid $uni-border-color-1;
    }
    .body-content {
      flex: 1;
      height: 0;
      display: flex;
      > div {
        flex: 1;
        width: 0;
      }
      .price-box {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0 40rpx;
        > div {
          padding: 10rpx 20rpx;
          width: 100%;
          display: flex;
          justify-content: space-between;
          color: $uni-text-color-1;
          font-size: 18rpx;
        }
      }

      .input-box {
        margin-top: 10rpx;
        border: 1rpx solid $uni-border-color-1;
        border-radius: 8rpx;
      }
      .active {
        border-color: $uni-color-primary;
      }

      .keyboard {
        padding: 20rpx;
        background: #f0f2f5;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8rpx;
        .jian {
          width: calc(33.3333% - 8rpx);
          aspect-ratio: 2 / 1;
          border-radius: 6rpx;
          display: flex;
          align-items: center;
          justify-content: center;
          background: $uni-text-color-inverse;

          font-size: 18rpx;
          color: $uni-text-color-1;

          &:active {
            background-color: #f5f5f5;
          }
        }
      }
    }

    .body-footer {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      padding: 10rpx 0;
      padding-right: 10rpx;
      border-top: 1rpx solid $uni-border-color-1;
      > div {
        width: 120rpx;
        height: 50rpx;
        line-height: 50rpx;
        text-align: center;
        border-radius: 8rpx;
        font-size: 18rpx;
        border: 1rpx solid $uni-border-color-1;
        margin-right: 20rpx;
      }
      .confirm {
        border: 0;
        background: $uni-color-primary;
        color: $uni-text-color-inverse;
      }
    }
  }
}
</style>
